<template>
	<view class="mask" v-show="show">
		<view class="timePeriod" v-show="show">
			<view class="flex flex-jcsb h76">
				<view class="" @click="cancel">取消</view>
				<view class="c69db7c" @click="submit">确定</view>
			</view>
			<picker-view  :indicator-style="'height:50px'" :value="value" @change="bindChange" class="picker-view">
				<picker-view-column >
					<view class="item" v-for="(item,index) in hours" :key="index">{{item}}时</view>
				</picker-view-column>
				<view class="sym">:</view>
				<picker-view-column>
					<view class="item" v-for="(item,index) in seconds" :key="index">{{item}}分</view>
				</picker-view-column>
				<view class="sym">-</view>
				<picker-view-column>
					<view class="item" v-for="(item,index) in hours" :key="index">{{item}}时</view>
				</picker-view-column>
				<view class="sym">:</view>
				<picker-view-column>
					<view class="item" v-for="(item,index) in seconds" :key="index">{{item}}分</view>
				</picker-view-column>
			</picker-view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "",
		data() {
			let hours = [], seconds = [];
			for (let i = 0; i < 24; i++) {
				hours = [].concat(hours, i < 10 ? "0" + i : i);
			}

			return {
				hours,
				seconds:['00','30'],
				value: [0, 0, 0, 0],
			}
		},
		props: {
			show:{
				type:Boolean,
				default:false,
			}
		},
		methods: {
			// 取消选择时间
			cancel(){
				this.$emit('cancel',false);
			},
			// 点击确定
			submit(){
				let h1 = this.value[0] <10 ? '0'+this.value[0] :this.value[0],
				s1 = this.seconds[this.value[1]],
				h2= this.value[2] <10 ? '0'+this.value[2] :this.value[2],
				s2 = this.seconds[this.value[3]];
				
				if((h1 > h2) ||( h1==h2 && s1 >= s2 )){
					uni.showToast({
						title:"结束时间小于开始时间",
						icon:'none'
					})
					return false;
				}
				
				
				this.$emit('submit',`${h1}:${s1}-${h2}:${s2}`);
				this.value = [0, 0, 0, 0];
			},
			// change 事件
			bindChange(e) {
				this.value = e.detail.value
			},
		}
	}
</script>

<style lang="scss" scoped>
	.timePeriod {
		width: 100%;
		height: 540rpx;
		background-color: #fff;
		position: absolute;
		bottom: 0;
		left: 0;
		padding: 20rpx;
		transform: translateY(100%);
		animation: up 0.4s linear forwards;
		.picker-view {
			width: 710rpx;
			height: 400rpx;
			margin-top: 20rpx;
		}
		.sym,
		.item {
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
		}
	}
	
	@keyframes up{
		from{
			transform: translateY(100%);
		}
		to{
			transform: translateY(0);
		}
	}

</style>
